//
//  FLLRecommenTalentTableViewCell.m
//  FLLGodOfCooking
//
//  Created by LL.F on 16/9/19.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLRecommenTalentTableViewCell.h"
#import "FLLPresentTopicsCollectionViewCell.h"
#import "FLLMacro.h"

@interface FLLRecommenTalentTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end
@implementation FLLRecommenTalentTableViewCell

- (void)awakeFromNib {
    
    self.layout.minimumInteritemSpacing = CellMargin;
    self.layout.minimumLineSpacing = 0;
    self.layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.collectionView registerNib:[UINib nibWithNibName:@"FLLPresentTopicsCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"presentTopicsCollectionCell"];
}
- (void)layoutSubviews
{

    [super layoutSubviews];
    [self layoutIfNeeded];
    self.userImageView.layer.masksToBounds = YES;
    self.userImageView.layer.cornerRadius = self.userImageView.bounds.size.height / 2.0;
    self.specialIcon.layer.masksToBounds = YES;
    self.specialIcon.layer.cornerRadius = self.specialIcon.bounds.size.height / 2.0;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.collectionData.count != 0) {
        return 3;
    }
    return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    FLLPresentTopicsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"presentTopicsCollectionCell" forIndexPath:indexPath];
    [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:self.collectionData[indexPath.row].image] placeholderImage:[UIImage imageNamed:@"菜谱详情加载"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
    return cell;
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{

    CGFloat width = (SCREEN_WIDTH - 2 * CellMargin ) / 3.0 ;
    CGFloat height = SCREEN_WIDTH / 3.0;
    return CGSizeMake(width, height);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *idString = self.collectionData[indexPath.row].id_Data;
    self.idBlock(idString);
}
- (void)setCollectionData:(NSMutableArray<RecommendTalentPost *> *)collectionData
{

    _collectionData = collectionData;
    [self.collectionView reloadData];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
